#include<iostream>
#include"LockGuard.hpp"

using std::cout;
using std::endl;

int gt = 100000;
pthread_mutex_t mutex_ = PTHREAD_MUTEX_INITIALIZER;

void* getticket(void* args)
{
    LockGuard lg(&mutex_);
    while(gt > 0)
    {
        if(gt > 0)
        {
            gt--;
            cout<<static_cast<const char*>(args)<<"get a ticket"<<" "<<"left ticket: "<<gt<<endl;
        }
        else
        {
            break;
        }
    }
    return nullptr;
}

int main()
{
    pthread_t th1,th2;
    pthread_create(&th1,nullptr,getticket,(void*)"th1");
    while(1)
    {
	    if(gt == 0){cout<<"tickets sold out"<<endl;break;}
    }
    return 0;
}
